<template>
  <div>
    <el-form :inline="true" v-model="args">
      <el-form-item label="合同编号">
        <el-input v-model="args.id"></el-input>
      </el-form-item>
      <el-form-item label="合同金额">
        <el-input v-model="args.contract_amount" type="number"></el-input>
         
      </el-form-item>
       <el-form-item label="">
      
         <el-input v-model="args.contract_amount2" type="number"></el-input>
      </el-form-item>
      <el-form-item label="项目名称">
        <el-input v-model="args.projectName" @focus="ProjectName"></el-input>
        <el-input v-model="args.pid" v-if="false"></el-input>
      </el-form-item>
      <el-form-item label="合同名称">
        <el-input v-model="args.contract_name"></el-input>
      </el-form-item>
      <el-form-item>
        <el-select v-model="args.order">
          <el-option label="自定义排序" value=""></el-option>
          <el-option
            label="登记时间从高到低"
            value="create_date.desc"
          ></el-option>
          <el-option label="登记时间从低到高" value="create_date.asc"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="签订人">
        <el-input v-model="args.contract_signatory"></el-input>
      </el-form-item>
      <el-form-item>
        <el-select v-model="args.approve_status">
          <el-option label="选择审批状态" value=""></el-option>
          <el-option label="未提交" value="0"></el-option>
          <el-option label="审批中" value="1"></el-option>
          <el-option label="审批不通过" value="2"></el-option>
          <el-option label="审批通过" value="3"></el-option>
          <el-option label="作废" value="4"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getLeaseContract()">查询</el-button>
      </el-form-item>
    </el-form>

    <div>
      <el-table :data="leaseContract" style="width: 100%">
        <el-table-column prop="id" label="编号" width="180">
        </el-table-column>
        <el-table-column prop="contractName" label="合同名称" width="180">
        </el-table-column>
        <el-table-column prop="contractAmount" label="金额" > </el-table-column>
        <el-table-column prop="providerId" label="供应商"> </el-table-column>
        <el-table-column prop="pId" label="所属项目" :formatter="projectNameFormater"> </el-table-column>
        <el-table-column prop="contractSignatory" label="签订人"> </el-table-column>
        <el-table-column prop="createDate" label="日期"> </el-table-column>
        <el-table-column prop="approveStatus" label="流程状态"> 
            <template slot-scope="scope">
            {{scope.row.approveStatus=='1'?'审批中':scope.row.approveStatus=='2'?'审批不通过':'审批通过'}}

        </template>
        </el-table-column>

              <el-table-column label="操作">
           <template slot-scope="scope">
          <el-dropdown trigger="click" @command="handleCommand">
            <span class="el-dropdown-link" style="color:grey">操作
            <i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <!-- v-if="scope.row.applyforApprovalStatus=='1'"  -->
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item   :command='{type:"del",row:scope.row}'><span>删除</span></el-dropdown-item>
            <el-dropdown-item   :command='{type:"update",row:scope.row}'><span>修改</span></el-dropdown-item>
            
          </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
      </el-table>
    </div>
         <el-dialog :visible.sync="projectTableVisible">
        <project-info-list v-on:row="row" v-if="projectTableVisible"></project-info-list>
         </el-dialog>
  </div>
</template>

<script>

import leaseContract from "../../model/hyh/LeaseaContract.js";
const lc = new leaseContract();

import LeasePlan from '../../model/hyh/LeasePlan.js'
const lp=new LeasePlan()

//使用项目明细组件

 import projectInfoList from '../common/projectInfo/ProjectInfoList'
export default {
  components: { projectInfoList },
  data() {
    return {
      args: {
        id: "",
        contract_amount:'',
        contract_amount2:'',
        pid: "",
        projectName: "",
        contract_signatory: "",
        order: "",
        approve_status: "",
      },
      leaseContract: [],
      projectInfo:[],
      projectTableVisible:false
    };
  },
  methods: {
     row(row){
                this.projectTableVisible=false
                this.args.projectName=row.projectName
                this.args.pid=row.id
               
          },
      //查询项目信息
    ProjectName() { 
       
      this.projectTableVisible = true;
    },
    getLeaseContract() {
      lc.getLeaseContract(this.args).then((response) => {
        this.leaseContract = response.data;
      });
    },
      //查询项目名称
    getProjectInfo(){
        lp.getProject().then((response)=>{
          this.projectInfo=response.data
      })
    },
  
    projectNameFormater(row){
     
      for(let i=0;i<this.projectInfo.length;i++){
        if(row.pid==this.projectInfo[i].id){
          return this.projectInfo[i].projectName;
        }
      }
     
    },
      handleCommand(command){
        if(command.type=="del"){
          this.row=command.row
         lc.delLeaseContract(this.row.id).then(()=>{
            this.getLeaseContract();
         })
        }

      }
  },
  created() {
    this.getLeaseContract();
    this.getProjectInfo()
  
  },
};
</script>

<style>
</style>